<?php

namespace app\admin\model;

use app\admin\model\BaseModel;


class Purchase extends BaseModel
{

    protected $name = "purchase";
    protected $pk = "id";
    // 追加属性
    protected $deleteTime = false;

    protected $append = [
        'admin_title',
        'applytype_title',
        'applystatus_title',
    ];


    public function getAdminTitleAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['admin_id']) ? $data['admin_id'] : '');
        $admin = table('system_admin')->where(['id' => $data['admin_id']])->find();
        return isset($admin['nickname']) ? $admin['nickname'] : '未分配';
    }

    public function getApplytypeTitleAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['apply_type']) ? $data['apply_type'] : '');
        $list = ['1' => '采购申请', '2' => '手动申请'];
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getApplystatusTitleAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['apply_status']) ? $data['apply_status'] : '');
        $list = ['1' => '待审', '2' => '通过审核', '3' => '驳回审核'];
        return isset($list[$value]) ? $list[$value] : '';
    }
}
